var SysLogManaged = function() {
	return {
		datatable : null,
		init : function() {
			$("#stime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m-d H:i"});
			$("#etime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m-d H:i"});
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var logTable = $("#logListTable").dataTable({
				"sAjaxSource" : ctx + "/sysLog/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {
						page : 1,
						start : 0,
						rows : 10,
						params : {}
					};
					
					if($('#userName_i').val()){
						postData.params.userName_i = "%"+($('#userName_i').val()).replace(/\s/g,"%")+"%";
					}
					
					if($('#stime').val()){
						postData.params.stime = $('#stime').val()+":00";
					}
					if($('#etime').val()){
						postData.params.etime = $('#etime').val()+":59";
					}
					
					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}

					$.ajax({
						"dataType" : 'json',
						"cache": false,
						"type" : "POST",
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
						{
							"data" : "index",
							"aTargets" : [ 0 ]
						},{
							"data" : "userName",
							"aTargets" : [ 1 ]
						},{
							"aTargets" : [ 2 ],
							"mRender" : function(data, type, full) {
								return new Date(full.createdTime).format("yyyy-MM-dd hh:mm:ss");
							}
						},{
							"data" : "methods",
							"aTargets" : [ 3 ],
						},{
							"data" : "url",
							"aTargets" : [ 4 ],
						},{
							"aTargets" : [ 5 ],
							"mRender" : function(data, type, full) {
								return "<div style='word-break: break-all;'>"+full.params+"</div>";
							}
						}]
			});
			this.datatable = logTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },initListener:function(){
			/**
			 * 监听开关事件
			 */
			$("#searchBtn").click(function() {
				SysLogManaged.reSearch();
				return false;
			});
			$("#clearBtn").click(function() {
				$("#searchForm")[0].reset();
				return false;
			});
		}
	};

}();